﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>

    <style>
        .li_style {
            list-style: none;
            margin: 0;
            padding: 0;
            padding-top: 20px;
            height: 50px;
            padding-left: 50px;
            float: left;
        }

        .ul_style {
            list-style: none;
            margin: 0;
            padding: 0;
            padding-top: 20px;
            height: 50px;
            padding-left: 50px;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <form action="">
                    <div style="width: 80%; padding-top: 50px; padding-left: 50px">
                        <div style="padding: 20px;border: solid 0.5px;box-shadow: 0 0 5px 3px rgba(209, 209, 255, 0.5);border-radius: 10px">
                            <div>
                                <span style="font-size: 15px;font-weight: bold">注意事项：</span>
                                <br/>
                                <span style="font-size: 14px; line-height: 20px;padding-left: 20px">
                                    · 切换设备推送数据的IP和端口，一定要将IP和端口输入正确。
								</span>
                            </div>
                            <br/>
                            <div>
                                <label style="float:left;padding-right: 10px">
                                    <span class="lbl">IMEI:</span>
                                </label>
                                <input type="text" name="imei" id="imei" placeholder="输入IMEI/MEID" style="width: 150px;">
                                <br/>
                                <label style="float:left;padding-right: 10px">
                                    <span class="lbl">IP/PORT:</span>
                                </label>
                                <input type="text" name="pushDataIp" id="pushDataIp" placeholder="输入IP地址" style="width: 150px;">
                                <input type="text" name="pushDataPort" id="pushDataPort" placeholder="输入端口" style="width: 70px;">
                            </div>
                           <%-- <br/>
                            <br/>
                            <div style="height: 50px; font-size: 14px;color: red; ">
                                <span id="singleResult"
                                      style="display: none;float: left;margin-right: 10px;font-weight: bold"></span>
                                <span id="moreResult"
                                      style="display: none;float: left;margin-right: 10px;font-weight: bold"></span>
                                <input type="button" id="foundExcelUrl" value="下载存在号码文件" onclick="download(0)"
                                       style="display: none;float: left;background-color: #0c76cb;margin-right: 10px;color: white">
                                <input type="button" id="foundNotJurisdictionExcelUrl" value="下载存在但无权访问的号码文件"
                                       onclick="download(4)"
                                       style="display: none;float: left;background-color: #0c76cb;margin-right: 10px;color: white">
                                <input type="button" id="notFoundExcelUrl" value="下载不存在号码文件" onclick="download(1)"
                                       style="display: none;float: left;background-color: #0c76cb;margin-right: 10px;color: white">
                            </div>--%>
                            <div style="height: 50px; font-size: 14px;color: red; ">
                                <span id="promptMsg" style="display: none;float: left;margin-right: 10px;font-weight: bold"></span>
                            </div>
                        </div>
                        <div style="margin-top: 30px;margin-left: 100px">
                            <input class="btn btn-primary" type="button" onclick="changeAddress()" value=切换 id="submitBut">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(top.hangge());
</script>

<script type="text/javascript">
    //保存
    function changeAddress() {
        var formData = new FormData();
        var imei = $("#imei").val();
        var ip = $("#pushDataIp").val();
        var port = $("#pushDataPort").val();
        if (imei == "") {
            $("#imei").tips({
                side: 3,
                msg: '请输入imei号',
                bg: '#AE81FF',
                time: 2
            });
            $("#imei").focus();
            return false;
        }
        if(ip == "" || !validateIPv4(ip)){
            $("#pushDataIp").tips({
                side: 3,
                msg: '请输入格式正确的ip',
                bg: '#AE81FF',
                time: 2
            });
            $("#pushDataIp").focus();
            return false;
        }
        if(port == "" || !validatePort(port)){
            $("#pushDataPort").tips({
                side: 3,
                msg: '请输入格式正确的端口',
                bg: '#AE81FF',
                time: 2
            });
            $("#pushDataPort").focus();
            return false;
        }
        formData.append("imei", imei);
        formData.append("ip",ip);
        formData.append("port",port);
        $("#submitBut").attr("disabled", true);
        $("#promptMsg").css("display", "none");
        $.ajax({
            type: "post",
            url: "/device/changeAddress",
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                $("#submitBut").attr("disabled", false);
                $("#promptMsg").css("display", "block");
                $("#promptMsg").text(data.msg);
            },
            error: function(data){
                $("#promptMsg").text(data.msg);
                $("#submitBut").attr("disabled", false);
            }
        })
    }

    function validateIPv4(ip) {
        var ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
        return ipv4Regex.test(ip);
    }

    // 验证端口号（范围：1-65535）
    function validatePort(port) {
        var portNumber = parseInt(port, 10);
        return portNumber >= 1 && portNumber <= 65535;
    }

</script>
</body>
</html>
